package gui.applets;

import java.applet.Applet;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.TextField;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class AppletRadioCheck extends Applet{
	TextField tf=new TextField(30);
	CheckboxGroup group=new CheckboxGroup();
	Checkbox cb[]={
			new Checkbox("Checkbox 1"),
			new Checkbox("Checkbox 2"),
			new Checkbox("Checkbox 3")
	};
	
	Checkbox cb4=new Checkbox("four",group,false);
	Checkbox cb5=new Checkbox("five",group,false);
	Checkbox cb6=new Checkbox("six",group,false);
	
	public void init(){
		tf.setEditable(true);
		this.add(this.tf);
		
		ILCheck il =new ILCheck();
		for(int i=0;i<cb.length;i++){
			this.cb[i].addItemListener(il);
			this.add(this.cb[i]);
		}
		
		cb4.addItemListener(new IL4());
		cb5.addItemListener(new IL5());
		cb6.addItemListener(new IL6());
		
		this.add(cb4);
		this.add(cb5);
		this.add(cb6);
	}
	
	class ILCheck implements ItemListener {

		@Override
		public void itemStateChanged(ItemEvent e) {
			for (int i = 0; i < cb.length; i++) {
				if (e.getSource().equals(cb[i])) {
					tf.setText("Check box" + (i + 1));
					return;
				}
			}
		}

	}
	
	class IL4 implements ItemListener{

		@Override
		public void itemStateChanged(ItemEvent e) {
			tf.setText("Radio button four");
		}
		
	}

	class IL5 implements ItemListener{

		@Override
		public void itemStateChanged(ItemEvent e) {
			tf.setText("Radio button five");
		}
		
	}
	
	class IL6 implements ItemListener{

		@Override
		public void itemStateChanged(ItemEvent e) {
		 tf.setText("Radio button six");
		}
		
	}
}
